package com.qf.sl.youshare.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.qf.sl.youshare.R;

import java.util.List;
import java.util.Map;

/**
 * Created by IDEA
 * User : sl
 * on 2015/2/5.
 * 8:58
 */
public class FunctionAdapter extends BaseAdapter {

    private Context context;
    private List<Map<String,?>> list;

    public FunctionAdapter(Context context, List<Map<String, ?>> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);

        View ret = inflater.inflate(R.layout.item_main_enter_point,parent,false);

        int height = (parent.getHeight() - 10) / 2;

        LinearLayout bgLayout = (LinearLayout) ret.findViewById(R.id.item_enter_point_bg);
        ImageView iconView = (ImageView) ret.findViewById(R.id.item_enter_point_icon);
        TextView titleView = (TextView) ret.findViewById(R.id.item_enter_point_title);

        Map<String, ?> map = list.get(position);

        int bg = (Integer)map.get("bg");
        int icon = (Integer)map.get("icon");
        String title = (String)map.get("title");

        ret.setMinimumHeight(height);
        bgLayout.setBackgroundResource(bg);
        iconView.setBackgroundResource(icon);
        titleView.setText(title);

        return ret;
    }

}
